import { Options } from "./system.interface";
import type { VTActor } from "cax-base";
import {
  MeshCreateOptions,
  RemeshOptions,
  CheckOptions,
  FileLoadOptions,
  SelectedPartsOptions,
  MODEL_TYPE,
  AnalysisOptions,
  MidSurfaceOptions,
  IDManagerOptions,
  WasherFindOptions,
  WasherCreateOptions,
  WasherSetHoleOptions,
  WasherClearOptions,
  Meshextrude3dCreateOptions,
  Meshextrude2dPreviewOptions,
  Meshextrude2dCreateOptions,
  FillHoleOptions,
  EdgePartitionOptions,
  MidSurfaceThicknessOptions,
  PastenodeApplyOptions,
  FileSaveOptions,
  Sweep3dOptions,
  trimOptions,
  TransformUpdateOptions,
  FreebodyReadFileOptions,
  FreebodyApplyOptions,
  FreebodyEntity,
  FreebodyFindNodesOptions,
  FreebodyEnterOptions,
  FreebodyTableDataOptions,
} from "../interface";
import { BActor } from "cax-base";
import { TPoint } from "../Actors/TMeshPoint";
export interface API_CHECK {
  checkD2: () => Promise<any>;
  deleteD2: (id: number) => Promise<any>;
}
export interface API_FILE {
  stp_or_bdf_file_load: (FileLoadOptions: FileLoadOptions) => Promise<any>; // 格宇支持stp文件
  // vtk_file_load: (path: string, type: MODEL_TYPE) => Promise<boolean>;
  // stl_file_load: (path: string, type: MODEL_TYPE) => Promise<boolean>;
  // ply_file_load: (path: string, type: MODEL_TYPE) => Promise<boolean>;
  load: (
    path: string,
    type: MODEL_TYPE,
    callback?: () => void
  ) => Promise<VTActor>;
  save: (options: FileSaveOptions) => Promise<string>;
  download: (filename: string, fileType: string) => Promise<string>;
}

export interface API_MODEL {
  add: (actor: BActor) => void;
  remove: (actor: BActor) => void;
  clear: () => void;
  mask: (partId: number) => void;
  unmask: (partId: number) => void;
  // unmask: (partId: number) => void;
  info: () => Promise<any>;
}

export interface API_DEFEATURE {
  counter_bore: () => Promise<any>;
  face_fillet: () => Promise<any>;
  analysis_hole: (options: AnalysisOptions) => Promise<any>;
  mid_surface: (options: MidSurfaceOptions) => Promise<any>;
  id_manager: (options: IDManagerOptions) => Promise<any>;
  mid_surface_thickness: (options: MidSurfaceThicknessOptions) => Promise<any>;
  show_mid_surface_thickness: (options: boolean) => Promise<any>;
}
export interface API_EDGE {
  edge_partition: (options: EdgePartitionOptions) => Promise<any>;
  edge_mesh_bias: (options: {
    entityId: number[];
    meshCtrl: EdgePartitionOptions;
  }) => Promise<any>;
  get_ratio: (options: number) => Promise<any>;
  leave: (options?: string) => Promise<any>;
}

export interface API_MESH {
  create: (options: MeshCreateOptions) => Promise<boolean>;
  remesh: (options: RemeshOptions) => Promise<boolean>;
  check: (options: CheckOptions) => Promise<boolean>;
  freeEdgeCheck: (options: any) => Promise<boolean>;
  clear: () => Promise<boolean>;
  merge: (partId: number, cellId1: number, cellId2: number) => Promise<any>;
  split: (options: any) => Promise<any>;
  detach: (options: any) => Promise<any>;
  hide_all: () => void;
  fillHole: (options: FillHoleOptions) => Promise<any>;
  joinMesher: (options?: any) => Promise<any>;
  show_all: () => void;
  quality: (type: string, threshold: number) => Promise<any>;
  normal_get: (ids: number[]) => Promise<any>;
  normal_show: (
    eids: number[],
    normals: number[],
    factor: number,
    color: number[]
  ) => void;
  normal_reverse: (ids: number[]) => Promise<any>;
  normal_align: (ids: number[]) => Promise<any>;
  normal_hide: () => void;
  organized: (options: any) => Promise<any>;
  cfdMeshCreate: (options: any) => Promise<any>;
  wrapperMeshCreate: (options: any) => Promise<any>;
  offset: (options: any) => Promise<any>;
  sweep3d: (options: Sweep3dOptions) => Promise<any>;
  setSelectSinglePoint: (coordinate: number[], pointActor: any) => Promise<any>;
  getSelectSinglePoint: () => Promise<{
    coordinate: number[];
    pointActor: any;
  }>;
  setSelectSingleLine: (
    lineCoordinate: number[],
    lineActor: any
  ) => Promise<any>;
  getSelectSingleLine: () => Promise<{
    lineCoordinate: number[];
    lineActor: any;
  }>;
}
export interface API_WASHER {
  create: (options: WasherCreateOptions) => Promise<any>;
  clear: (options?: WasherClearOptions) => Promise<any>;
  findpinhole: (options: WasherFindOptions) => Promise<any>;
  setHole: (options: WasherSetHoleOptions) => Promise<any>;
  enter: () => Promise<any>;
  leave: () => Promise<any>;
  select: () => Promise<any>;
}
export interface API_MESHEXTRUDE2D {
  addEntity: (options?: string) => Promise<any>;
  leave: (options?: string) => Promise<any>;
  clear: (options?: string) => Promise<any>;
  create: (options: Meshextrude2dCreateOptions) => Promise<any>;
  preview: (options: Meshextrude2dPreviewOptions) => Promise<any>;
  updateMethod: (options: string) => Promise<any>;
}
export interface API_MESHEXTRUDE3D {
  addEntity: (options?: string) => Promise<any>;
  leave: (options?: string) => Promise<any>;
  clear: (options?: string) => Promise<any>;
  create: (options: Meshextrude3dCreateOptions) => Promise<any>;
  updateMethod: (options: string) => Promise<any>;
}
export interface API_PASTENODE {
  enter: (options: string) => Promise<any>;
  leave: (option?: string) => Promise<any>;
  apply: (options: PastenodeApplyOptions) => Promise<any>;
  addNodes: (name: string, pointIds?: any[]) => Promise<any>;
  clear: () => Promise<any>;
}
export interface API_TETMESH {
  create: (options: any) => Promise<any>;
}
export interface API_CELL {
  create: (options: any) => Promise<any>;
  re_number: (options: any) => Promise<any>;
}
export interface API_GEOMETRY {
  delete: (value: number) => Promise<boolean>;
}

export interface API_VIEW {
  modeChang: (mode: VIEW_MODE) => void;
  autoAdapt: () => void;
  setEdgeColor: (v: boolean) => void;
}

export enum VIEW_MODE {
  WIREFRAME = "WIREFRAME",
  SURFACE = "SURFACE",
  POINTS = "POINTS",
  WIREFRAME_WITH_POINTS = "WIREFRAME_WITH_POINTS",
}

export interface API_STATE {
  set: (key: string, value: any) => Promise<boolean>;
  get: (key: string) => any;
  clear: () => void;
  get_selected_mesh_ids: () => number[];
}

export interface API_MEASURE {
  p2p: (
    id1: number,
    id2: number,
    partId1: number,
    partId2: number
  ) => Promise<any>;
}

export interface API_MASK {
  mask: () => void;
  reverse: () => Promise<string>;
  reverseAll: () => Promise<string>;
  unmaskAll: () => void;
}

export interface API_SELECTOR {
  selectMeshPointByClick: (index: number) => void;
  selectMeshPointByBox: (index: number) => void;
  selectMeshByClick: (index: number) => void;
  selectMeshByBox: (index: number) => void;
  clearAll: () => void;
}
export interface API_TRIM {
  trimFaceByLine: (options: trimOptions) => void; // 用边（特征线）切割面
  trimBodyByFace: (options: trimOptions) => void; // 固体分割（面）
  trimFaceByFace: (options: trimOptions) => void; // 面与面相互切割
  trimLineByNode: (options: trimOptions) => void; // 点到线的切割（面）
}

export interface API_CONFIG {
  connect: (name: string, url: string, path?: string) => void;
  disconnect: () => void;
}

export interface API_HOOKS {
  onConnected: (callback: () => void) => void;
  onDisconnected: (callback: () => void) => void;
  onEscKeyDown: (callback: () => void) => void;
}

export interface API_RENDER {
  render: () => void;
}

export interface API_MATERIAL {
  getAllMaterials: () => Promise<string>;
  createMaterial: (values: any) => Promise<string>;
  deleteMaterial: (id: number) => Promise<string>;
  getMaterialById: (id: number) => Promise<string>;
  modifyMaterial: (id: number, values: any) => Promise<any>;
  batchRenameMaterials: (
    prefix: any,
    suffix: any,
    materials: any
  ) => Promise<string>;
}
export interface API_LOAD_CONSTRAINTS {
  createLoadConstraints: (model_info: any) => Promise<string>;
  createBcs: (model_info: any) => Promise<string>;
  createDisplacement: (model_info: any) => Promise<string>;
  createForce: (model_info: any) => Promise<string>;
  createTemperatureSet: (model_info: any) => Promise<string>;
  addNormal: (values: any) => void;
  modifyForce: (values: any) => Promise<string>;
  modifyDisplacemnet: (values: any) => Promise<string>;
  getForceInfo: (id: any) => Promise<string>;
  getDisplacemnetInfo: (id: any) => Promise<string>;
  deleteForceSet: (delete_param: any) => Promise<string>;
  deleteTemperatureSet: (id: number) => Promise<string>;
  deleteItem: (delete_param: any) => Promise<string>;
  getAllLoadConstraints: () => Promise<string>;
  modifyTemperature: (id: number, values: any) => Promise<string>;
  setTemperature: (node: any, values: any) => Promise<string>;
}
export interface API_PROPERTY {
  getAllProperties: () => Promise<string>;
  createProperty: (values: any) => Promise<string>;
  deleteProperty: (id: number) => Promise<string>;
  getPropertyById: (id: number) => Promise<string>;
  modifyProperty: (id: number, values: any) => Promise<string>;
  asssignProperty: (entity_ids: number[], prop_id: number) => Promise<string>;
  batchRenameProperties: (
    prefix: any,
    suffix: any,
    properties: any
  ) => Promise<string>;
}

export interface API_SET {
  getAllSets: () => Promise<string>;
  createSet: (values: any) => Promise<string>;
  deleteSet: (id: number) => Promise<string>;
  getSetById: (id: number) => Promise<string>;
  modifySet: (id: number, values: any) => Promise<string>;
  addSet: (values: any, sets: any) => Promise<string>;
  plotNodeSet: () => void;
  plotElementSet: () => any;
}

export interface API_OUTPUTBLOCK {
  getAllOutputblocks: () => Promise<string>;
  createOutputblock: (values: any) => Promise<string>;
  deleteOutputblock: (id: number) => Promise<string>;
  getOutputblockById: (id: number) => Promise<string>;
  modifyOutputblock: (id: number, values: any) => Promise<string>;
  asssignOutputblock: (
    entity_ids: number[],
    prop_id: number
  ) => Promise<string>;
}

export interface API_CARD {
  getAllCards: () => Promise<string>;
  createCard: (values: any) => Promise<string>;
  deleteCard: (id: number) => Promise<string>;
  getCardById: (id: number) => Promise<string>;
  modifyCard: (id: number, values: any) => Promise<string>;
  asssignCard: (entity_ids: number[], prop_id: number) => Promise<string>;
  getElements: () => Promise<any>;
}

export interface API_COORDINATE {
  getAllCoordinates: () => Promise<string>;
  createCoordinate: (values: any) => Promise<string>;
  createNodeCoordinate: (values: any) => Promise<string>;
  createMaterialOrientation: (values: any) => Promise<string>;
  deleteCoordinate: (id: number) => Promise<string>;
  deleteNodeCoordinate: (id: number) => Promise<string>;
  deleteMaterialOrientation: (id: number) => Promise<string>;
  getCoordinateById: (id: number) => Promise<string>;
  modifyCoordinate: (
    nodes_info: any,
    name: string,
    setName: string
  ) => Promise<string>;
  modify_coordinatename: (id: number, values: any) => Promise<string>;
  modify_nodeCoordinate: (id: number, values: any) => Promise<string>;
  modifyMaterialOrientation: (id: number, values: any) => Promise<string>;
  set_nodeCoordinate: (node: any, values: any) => Promise<string>;
}

export interface API_ROD {
  crateRodUnit: (
    rodNode1: any,
    rodNode2: any,
    rodUnitType: any
  ) => Promise<string>;
}

export interface API_BEAM {
  crateBeamByNode: (leftNode: any, rightNode: any, values: any) => Promise<any>;
  crateBeamByLine: (values: any) => Promise<any>;
  undoBeam: (values: any) => Promise<any>;
}

export interface API_FIELD {
  createField: (values: any) => Promise<string>;
  deleteField: (id: number) => Promise<string>;
  modifyField: (id: number, values: any) => Promise<string>;
  load2minio: (filename: string, arrayBuffer: any) => Promise<any>;
  uploadFieldFile: (fileName: string, name: any, id: any) => Promise<any>;
  addFieldnodes: (node: any, values: any) => Promise<string>;
  showField: () => void;
  clearField: () => void;
}
export interface API_COLOR {
  set_entity_color: (entity_id: number, rgb: number[]) => void;
}

export interface API_PROJECT {
  load: (file: File) => Promise<boolean>;
  save: () => Promise<boolean>;
}
export interface API_FIND {
  findLoadByElem: () => Promise<string>;
}
export interface API_TRANSFORM {
  leave: (module: string) => Promise<boolean>;
  update: (options: TransformUpdateOptions) => Promise<any>;
}
export interface API_FREEBODY {
  leave: (options?: string) => Promise<boolean>;
  enter: (options: FreebodyEnterOptions) => Promise<any>;
  read_file: (options: FreebodyReadFileOptions) => Promise<any>;
  sets: () => Promise<any>;
  update_entities: (options: FreebodyEntity[]) => Promise<any>;
  find_nodes: (options: FreebodyFindNodesOptions) => Promise<any>;
  apply: (options: FreebodyApplyOptions) => Promise<any>;
  table_data: (options: FreebodyTableDataOptions) => Promise<any>;
}
